<template>
  <div class="app-container">
      <h2>宠物病历列表</h2>
      <!-- 查询 -->
      <el-form :inline="true" class="demo-form-inline">
         <el-form-item label="名称">
            <el-input  v-model="searchObj.name" placeholder="宠物主人名称"/>
         </el-form-item>
         <el-form-item label="预约项目">
         <el-select v-model="searchObj.reserveItem" placeholder="请选择预约项目">
        <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value">
        </el-option>
         </el-select>
        </el-form-item>

        <el-form-item label="状态">
         <el-select v-model="searchObj.status" placeholder="状态">
        <el-option
        v-for="item in statuss"
        :key="item.value"
        :label="item.label"
        :value="item.value">
        </el-option>
         </el-select>
        </el-form-item>

         <el-form-item label="预约时间">
        <el-date-picker
        v-model="searchObj.bufferTime"
        type="date"
        placeholder="选择日期">
        </el-date-picker>
    </el-form-item>

         <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
      </el-form>

       <!-- 工具条 -->
      <!-- <div>
         <el-button type="danger" size="mini" @click="removeRows()">批量删除</el-button>
      </div>  -->
      <div class="el-toolbar">
            <div class="el-toolbar-body" style="justify-content: flex-start;">
               <el-button type="danger" size="mini" @click="removeRows()">批量删除</el-button>&emsp; &emsp; 
                <a href="http://localhost:8201/admin/hosp/reserve/exportData" target="_blank">
                    <el-button type="text"><i class="fa fa-plus"/> 导出</el-button>
                </a>
            </div>
        </div>

      <!-- 预约列表 -->
      <el-table
      :data="list" stripe style="width: 100%" @selection-change="handleSelectionChange">
         <el-table-column type="selection" width="55"/>
         <el-table-column type="index" width="50" label="序号"/>
         <el-table-column prop="name" label="宠物主人名称"/>
         <el-table-column prop="phoneNumber" label="手机号码"/>
         <el-table-column prop="petType" label="宠物类型"/>
         <el-table-column prop="petAge" label="宠物年龄"/>
         <el-table-column v-if="false" prop="reserveItem" label="预约项目"/>
         <el-table-column prop="reserveTime" label="预约时间"/>
         <el-table-column prop="remark" label="病情描述"/>
         <el-table-column prop="doctorName" label="诊断医生"/>
         <el-table-column prop="diagnosis" label="诊断结果"/>
         <el-table-column prop="userId" label="用户"/>
         <el-table-column v-if="false" prop="bufferTime" label="预约时间"/>
         <el-table-column label="就诊状态" width="80">
            <template slot-scope="scope">
                     {{ scope.row.status === 1 ? '未就诊' : '已就诊' }}
            </template>
         </el-table-column>
         <el-table-column label="操作" width="280" align="center">
            <template slot-scope="scope">
               <el-button type="danger" size="mini" 
                  icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
               <!-- <el-button v-if="scope.row.status==1" type="primary" size="mini" 
                  icon="" @click="lockReserve(scope.row.id,0)">已完成</el-button> -->
               <!-- <el-button v-if="scope.row.status==0" type="danger" size="mini" 
                  icon="" @click="lockReserve(scope.row.id,1)">继续就诊</el-button> -->
            <!-- <router-link :to="'/diagnosis/edit/'+scope.row.id">
               <el-button type="primary" size="mini" icon="el-icon-edit">就诊病例</el-button>
            </router-link> -->
            </template>
         </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
      :current-page="current"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"/>
  </div>
</template>

<script>
import reserve from '@/api/reserve'
export default {
    //定义变量和初始值
    data() {
        return{
                current:1,//当前页
                limit:5,//每页显示记录数
                searchObj:{},//条件封装数据
                list:[],//每页数据集合
                total:0,//总记录数
                multipleSelection: [], // 批量选择中选择的记录列表
                options: [{//选择框数据
                  value: '',
                  label: '全部',
               },{//选择框数据
                  value: '预约挂号',
                  label: '预约挂号',
               },{
                  value: '健康体检',
                  label: '健康体检'
               }, {
                  value: '犬猫驱虫',
                  label: '犬猫驱虫'
               }, {
                  value: '宠物绝育',
                  label: '宠物绝育'
               }, {
                  value: '洗浴美容',
                  label: '洗浴美容'}],
               statuss: [{//选择框数据
                  value: '',
                  label: '全部',
               },{//选择框数据
                  value: '1',
                  label: '未就诊',
               },{
                  value: '0',
                  label: '已就诊'
               }],
            }
    },
    created() { //在页面渲染之前执行
    //一般调用methods定义的方法，得到数据
        this.getList()
    },
    methods: {
       //锁定和取消锁定
      lockReserve(id,status) {
         reserve.lockReserve(id,status)
            .then(response => {
               //刷新
               this.getList()
            })
      },
       //获取选择复选框的id值
      handleSelectionChange(selection) {
         this.multipleSelection = selection
      },
       //批量删除
      removeRows() {
         this.$confirm('此操作将永久删除医院是设置信息, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
         }).then(() => { //确定执行then方法
            var idList = []
            //遍历数组得到每个id值，设置到idList里面
            for(var i=0;i<this.multipleSelection.length;i++) {
               var obj = this.multipleSelection[i]
               var id = obj.id
               idList.push(id)
            }
            //调用接口
            reserve.batchRemoveReserve(idList)
               .then(response => {
                  //提示
                  this.$message({
                     type: 'success',
                     message: '删除成功!'
                  })
                  //刷新页面
                  this.getList(1)
               })
         })
      },
        getList(page=1){
            this.current = page
            reserve.getReserveDiagnosisList(this.current,this.limit,this.searchObj)
            .then(response => { //请求成功response是接口返回数据
            //返回集合赋值list
                this.list = response.data.records
                //总记录数
                this.total = response.data.total
                console.log(response)
            })//请求成功
            .catch(error => {//请求失败
                console,log(error)
            })//请求失败
        },

        //删除医院设置的方法
      removeDataById(id) {
         this.$confirm('此操作将永久删除医院是设置信息, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
         }).then(() => { //确定执行then方法
            //调用接口
            reserve.deleteReserve(id)
               .then(response => {
                  //提示
                  this.$message({
                     type: 'success',
                     message: '删除成功!'
                  })
                  //刷新页面
                  this.getList(1)
               })
         })
      }

    }

}
</script>

<style>

</style>